import QtQuick 1.0

Item {
    id: progressIndicator

    property int value: 0 // Percentage [0, 100]
    property string progressColor: "#44a51c"
    property string readyColor: "#0033cc"

    Behavior on value {
        NumberAnimation { duration: root.constants.shortAnimationDuration }
    }

    Rectangle {
        id: shadowRectangle
        anchors.fill: parent
        radius: height
        color: value < 100 ? progressColor : readyColor
        opacity: root.constants.shadowOpacity
        smooth: true
    }

    Rectangle {
        id: progressIndicatorBar

        property string barColor: value < 100 ? progressColor : readyColor

        width: shadowRectangle.height - root.constants.defaultBorderWidth * 2
        height: shadowRectangle.width - root.constants.defaultBorderWidth * 2
        anchors.centerIn: parent
        radius: shadowRectangle.radius
        rotation: -90
        smooth: true

        gradient: Gradient {
            GradientStop { position: 0.0; color: progressIndicatorBar.barColor }
            GradientStop {
                position: value < 100 ? value / 100 : 1.0;
                color: progressIndicatorBar.barColor
            }
            GradientStop {
                position: value < 100 ? value / 100 + 0.01 : 1.0;
                color: value < 100 ?
                           root.constants.defaultBackgroundColor :
                           progressIndicatorBar.barColor
            }
            GradientStop {
                position: 1.0;
                color: value < 100 ?
                           root.constants.defaultBackgroundColor :
                           progressIndicatorBar.barColor
            }
        }
    }

    Text {
        anchors.fill: parent
        color: root.constants.defaultForegroundColor
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        font.pixelSize: root.constants.defaultFontPixelSize
        text: {
            if (value < 0) {
                value = 0;
            }
            else if (value > 100) {
                value = 100;
            }

            value + " %"
        }
    }
}

// End of file.
